package com.beauty.dressing.module.main.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.framework.common.utils.IKeyboardUtils;
import com.beauty.dressing.common.base.BaseActivity;
import com.beauty.dressing.logic.manager.SharedPreferencesManager;
import com.beauty.dressing.module.common.view.InputEditDialog;
import com.beauty.dressing.rxandroid.rxbus.RxBus;
import com.beauty.dressing.rxandroid.rxbus.RxConstants;
import com.beauty.dressing.R;

/**
 * 用户输入限制口数
 */

public class LimitActivity extends BaseActivity {
    private Button mLimitBtn;
    private TextView mLimitNum;
    private InputEditDialog mDialog;
    public static void startActivity(Context context){
        Intent intent = new Intent(context,LimitActivity.class);
        context.startActivity(intent);
    }
    @Override
    public void setContentView() {
        setContentView(R.layout.activity_limit_input);
    }

    @Override
    public void findView() {
        findViewById(R.id.left_img_btn).setOnClickListener(this);
        mLimitBtn = (Button) findViewById(R.id.limit_btn);
        mLimitBtn.setOnClickListener(this);
        mLimitNum = (TextView) findViewById(R.id.limit_num);
        mDialog = new InputEditDialog(context,mEditListener);
    }

    @Override
    public void initData() {
        int limit = new SharedPreferencesManager().read(SharedPreferencesManager.KEY_LIMIT_NUM,0);
        mLimitNum.setText(String.valueOf(limit));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.left_img_btn:
                finish();
                break;
            case R.id.limit_btn:
                if (!mDialog.isShowing()){
                    mDialog.show();
                }
                break;
        }
    }

    private InputEditDialog.OnEditListener mEditListener = new InputEditDialog.OnEditListener(){

        @Override
        public void editResult(String result,int num) {
            RxBus.getDefault().postWithCode(RxConstants.ACTION_LIMIT,num);
            finish();
        }
    };
}
